
/*	brief The Transform class store the object position and rotation in 3D space		*/
Transform	=	function ()
{
	/************************************/
	/*			Properties				*/
	/************************************/
	
	/*! Determine if the transform is used by a View. If so, the result Matrix is : 
	/*	m_Rotation * m_Position instead of m_Position*m_Rotations			*/
	
	this.m_IsView			=	0;		
	
	this.m_Position			=	new Vec4();         /*!< Vector3 Position                           */
	this.m_EulerAngles     	= 	new Vec4(); 		/*!< Store current euler angles values          */
	
	//	Just a word about euler angles :	To Euler, every rotation can be factorize in 3 rotations, one for each
	//	repere axis
	
	this.m_Forward    		= 	new Vec4();   		/*!< Forward vector                             */

	this.m_RotationMatrix 	= 	new Matrix4();  	/*!< Matrix Storing the position in space       */
	this.m_PositionMatrix  	= 	new Matrix4(); 		/*!< Matrix storing the rotation of the object  */

	this.m_TransformMatrix 	= 	new Matrix4(); 		/*!< Matrix storing position then rotat  (m_PositionMatrix* m_RotationMatrix) */

	this.Init();
}

/************************************/
/*          Constructors            */
/************************************/

	/*!	brief	Start position and Euler angle		*/
	Transform.prototype.Init= function()
	{
		this.m_Forward 		=  new 	Vec4(0.0,0.0,-1.0,1.0);
		this.m_EulerAngles 	=  new	Vec4(0.0,0.0,0.0,0.0);
	}
	
	/************************************/
	/*          Get/Set                 */
	/************************************/
		
		/*!	brief Return Object's current position in world space	*/
		Transform.prototype.GetPosition	=	function()
		{
			return this.m_Position;
		}
		
		/*!	brief Return Object's current position in world space	*/
		Transform.prototype.SetPosition = function(x, y, z)
		{
			this.m_Position = new Vec4(x, y, z, 1.0);
			this.m_PositionMatrix = Matrix4.Translation(this.m_Position.x, this.m_Position.y, this.m_Position.z);
			this.UpdateTransformMatrix();
		}
		
		// Return Euler values
		Transform.prototype.GetEulerAngles	=	function()
		{
			return this.m_EulerAngles;
		}
		
		Transform.prototype.SetEulerAngles	=	function(x, y, z)
		{
			this.m_EulerAngles = new Vec4(x,y,z,1.0);
			this.m_RotationMatrix= (Quaternion.Euler(this.m_EulerAngles.x,this.m_EulerAngles.y,this.m_EulerAngles.z)).RotationMatrix();
			UpdateTransformMatrix();
		}
		

    /************************************/
    /*              Methods             */
    /************************************/

		Transform.prototype.UpdatePositionMatrix	=	function()
		{
			this.m_PositionMatrix	=	 Matrix4.Translation(this.m_Position.x, this.m_Position.y, this.m_Position.z);
		}
		
		/*!	Update the Transform Matrix		*/
		Transform.prototype.UpdateTransformMatrix= function()
		{
			if(this.m_IsView == 1)
			{
				//this.m_TransformMatrix= this.m_PositionMatrix.MultMatrix(this.m_RotationMatrix);
				this.m_TransformMatrix= this.m_PositionMatrix;
			}
			else
			{
				//this.m_TransformMatrix= this.m_RotationMatrix.MultMatrix(this.m_PositionMatrix);
			}
			
		}

		/*!	Brief Translate the current object	*/
		Transform.prototype.Translate= function( x,  y,  z)
		{
			this.m_Position = new Vec4(this.m_Position.x+this.x, this.m_Position.y+y, this.m_Position.z+z, 1.0);
			this.m_PositionMatrix = Matrix4.Translation(this.m_Position.x, this.m_Position.y, this.m_Position.z);
			UpdateTransformMatrix();
		}

		Transform.prototype.RotateEuler= function( x,  y,  z)
		{
			this.m_EulerAngles		= 	new Vec4(this.m_EulerAngles.x+x,this.m_EulerAngles.y+y,this.m_EulerAngles.z+z,1.0);
			this.m_RotationMatrix	= 	(Quaternion.Euler(this.m_EulerAngles.x,this.m_EulerAngles.y,this.m_EulerAngles.z)).RotationMatrix();
			UpdateTransformMatrix();
		}

		Transform.prototype.ReturnModelMatrix = function()
		{
			return this.m_TransformMatrix.array;
		}
